package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.THost;
import com.ruoyi.system.service.THostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 主机表(THost)表控制层
 *
 * @author stone
 * @since 2022-04-15 17:15:53
 */
@Api(tags = "主机表(THost)")
@RestController
@RequestMapping("tHost")
@Slf4j
public class THostController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private THostService tHostService;

    /**
     * 分页查询
     *
     * @param tHost 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    @ApiOperation(value = "分页查询")
    public TableDataInfo list(THost tHost) {
        startPage();
        return getDataTable(this.tHostService.page(tHost));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "通过主键查询单条数据")
    public AjaxResult detail(@PathVariable("id") Integer id) {
        return AjaxResult.success(this.tHostService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tHost 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增数据")
    public AjaxResult add(@RequestBody THost tHost) {
        return toAjax(this.tHostService.insert(tHost));
    }

    /**
     * 编辑数据
     *
     * @param tHost 实体
     * @return 编辑结果
     */
    @PutMapping("/put")
    @ApiOperation(value = "编辑数据")
    public AjaxResult put(@RequestBody THost tHost) {
        return toAjax(this.tHostService.update(tHost));
    }

    /**
     * 删除数据
     *
     * @return 删除是否成功
     */
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除数据")
    public AjaxResult del(@PathVariable("ids") String ids) {
        return toAjax(this.tHostService.deleteByIds(ids));
    }

}
